package com.ljc.search.mq;

import com.ljc.config.RabbitConfig;
import com.ljc.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.logging.Logger;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: ljc
 * @Date:Created in 10:15 2022/2/24
 */
@Slf4j
@Component
@RabbitListener(queues = RabbitConfig.es_queue)
public class MqMessageHandler {
    @Autowired
    SearchService searchService;
    @RabbitHandler
    public void handler( PostMqIndexMessage message){
     log.info("mq收到一条消息:{}",message.toString());

     switch (message.getType()){
         case PostMqIndexMessage.CREATE_OR_UPDATE:
             searchService.createOrUpdateIndex(message);
             break;
         case PostMqIndexMessage.REMOVE:
             searchService.remove(message);
             break;
         default:
             log.error("没找到对应的消息类型!----->>>",message.toString());
             break;

     }
    }
}
